package com.neu.emp;

import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.neu.emile.tb_emp;

public class Demo01 {
		/**
		 *   通过jdbc完成emp表、dept表的数据查询（全表查询）；
		 */
	private static String url = "jdbc:mysql://localhost:3306/mjq";
	private static String userName = "root";
	private static String pass = "mysql";
	private static String driver = "com.mysql.jdbc.Driver";
	public static Connection conn;
//	public static PreparedStatement ps;
	static {
		try {
			Class.forName(driver);
			conn=DriverManager.getConnection(url,userName,pass);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	public static void select() throws SQLException {
		String sql = "select*from tb_emp ";
		Statement st= conn.createStatement();
		ResultSet rs =st.executeQuery(sql);
		while(rs.next()) {
			 int empno = rs.getInt(1);
			 String ename=rs.getString(2);
			 String job=rs.getString(3);
			 int mgr=rs.getInt(4);
			 String hiredate=rs.getString(5);
			 double sal=rs.getDouble(6);
			 double comm=rs.getDouble(7);
			 int deptno=rs.getInt(8);

			 System.out.println(empno);
			 System.out.println(ename);
			 System.out.println(job);
			 System.out.println(mgr);
			 System.out.println(hiredate);
			 System.out.println(sal);
			 System.out.println(comm);
			 System.out.println(deptno);
			
		}
	}
	public static void select1() throws SQLException {
		String sql = "select*from dept ";
		Statement st= conn.createStatement();
		ResultSet rs =st.executeQuery(sql);
		while(rs.next()) {
			int deptno = rs.getInt("deptno");
			String dname = rs.getString("dname");
			String loc = rs.getString("loc");
			System.out.println(deptno);
			System.out.println(dname);
			System.out.println(loc);
			}
		}
	public static void main(String[] args) throws SQLException {
		select();
		select1();
	}
}
